<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns="http://www.w3.org/1999/xhtml">
<head lang="en">
    <meta charset="UTF-8">
    <title>资源管理</title>
    <link rel="stylesheet" href="../../../assert/css/font.css" th:href="@{/assert/css/font.css}"/>
    <link rel="stylesheet" href="../../../assert/css/bootstrap.min.css" th:href="@{/assert/css/bootstrap.min.css}"/>
    <link rel="stylesheet" href="../../../assert/css/bootstrap-table.css" th:href="@{/assert/css/bootstrap-table.css}"/>
    <link rel="stylesheet" href="../../../assert/css/bootstrap-select.min.css"
          th:href="@{/assert/css/bootstrap-select.min.css}"/>
    <link rel="stylesheet" href="../../../assert/css/bootstrapValidator.css"
          th:href="@{/assert/css/bootstrapValidator.css}"/>
    <link rel="stylesheet" href="../../../assert/css/toastr.min.css" th:href="@{/assert/css/toastr.min.css}"/>
    <link rel="stylesheet" href="../../../assert/css/style.css" th:href="@{/assert/css/style.css}"/>
    <link rel="stylesheet" href="../../../assert/css/index.css" th:href="@{/assert/css/index.css(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"/>
    <link rel="stylesheet" href="../../../assert/css/common.css" th:href="@{/assert/css/common.css}"/>
</head>

<body class="laydate_body">
<a id="basePath" th:href="@{/}"></a>
<div class="wrapper wrapper-content">
    <div class="ibox">
    <!--<div class="con-ti'refresh'tle">-->
        <!--<h4>资源管理</h4>-->
    <!--</div>-->
    <div class="resourceCon">
        <div class="con-operation clearfix">
            <div class="cquery  clearfix">
                <div class="search_group">
                    <label class="control-label">父级资源：</label>
                    <div class="control-inline">
                        <select id="parentIdSearch" class="selectpicker" data-live-search="true"
                                data-live-search-style="begins" title="请选择资源" multiple>
                        </select>
                    </div>
                </div>
                <div class="search_group">
                    <div class="control-inline">
                        <div class="querySearch">
                            <input id="codeSearch" class="form-control" type="text" placeholder="请输入编码"/>
                            <input id="nameSearch" class="form-control" type="text" placeholder="请输入名称"/>
                        </div>
                    </div>
                </div>
                <div class="search_group">
                    <button id="searchBtn" type="button" class=" querybtn btn btn-danger">查询</button>
                    <button id="reset" type="reset" class="btn  btn-default">重置</button>
                </div>
            </div>
            <div class="obtns clearfix">
                <button class="btn btn-default" type="button" data-toggle="modal" data-target="#resourceModal" id="resourceBtn">
                    <i class="fa fa-plus"></i>资源
                </button>
                <button id="editBtn" class="btn btn-default" type="button">
                    <i class="fa fa-pencil"></i>修改
                </button>
                <button id="batchDeleteBtn" class="btn btn-default" type="button" data-toggle="modal"><i
                        class="fa fa-trash"></i>删除
                </button>
                <button id="batchOnBtn" class="btn btn-default" type="button"><i class="fa fa-power-off"></i>启用
                </button>
                <button id="batchOffBtn" class="btn btn-default" type="button"><i class="fa fa-stop"></i>停用
                </button>
            </div>
        </div>
        <!--资源管理table-->
        <table id="resourceTable"></table>
        <!-- 资源管理Modal -->
        <div class="modal fade" id="resourceModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
             data-backdrop=false>
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">资源管理</h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal" role="form" id="resouceForm">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">父级资源：</label>
                                <div class="col-sm-7">
                                    <select class="fresourcepicker selectpicker" name="parentid" id="addSelect">
                                        <option value="">请选择</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"><span class="respan">*</span>资源类型：</label>
                                <div class="col-sm-7">
                                    <select class="resourceTypepicker selectpicker" name="type" id="addTypeSelect">
                                        <option value="0">菜单</option>
                                        <option value="1">功能</option>
                                        <option value="2">页面元素</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"><span class="respan">*</span>编码：</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" name="code" placeholder="请输入编码">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"><span class="respan">*</span>名称：</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" name="name" placeholder="请输入名称">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label">访问地址/资源编码:</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" name="url" placeholder="请输入访问地址/资源编码">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label">imgSpan:</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" name="imgspan" placeholder="imgSpan">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="isort" class="col-sm-4 control-label"><span
                                        class="respan">*</span>排序:</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" name="orderno" placeholder="排序">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="isort" class="col-sm-4 control-label">描述:</label>
                                <div class="col-sm-7">
                                    <textarea class="form-control" name="description" id="isort"
                                              placeholder="描述"></textarea>
                                </div>
                            </div>
                            <button type="reset" class="btn btn-default" style="display: none"
                                    id="addResetBtn"></button>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="savebtn btn btn-primary" id="addSaveBtn">保存</button>
                        <button type="button" class="cancelbtn btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
        <!--修改modal -->
        <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
             data-backdrop=false>
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">修改资源</h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal" role="form" id="editResourceForm">
                            <input type="hidden" name="id" id="resourceId"/>
                            <div class="form-group">
                                <label class="col-sm-4 control-label">父级资源：</label>
                                <div class="col-sm-7">
                                    <select class="fresourcepicker selectpicker" name="parentid" id="editSelect">
                                        <option value="" selected>请选择</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"><span class="respan">*</span>资源类型：</label>
                                <div class="col-sm-7">
                                    <select class="resourceTypepicker selectpicker" name="type" id="editTypeSelect">
                                        <option value="0" selected>菜单</option>
                                        <option value="1">功能</option>
                                        <option value="2">页面元素</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"><span class="respan">*</span>编码：</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" name="code" placeholder="编码"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label">名称：</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" name="name" placeholder="名称"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label">访问地址：</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" name="url" placeholder="访问地址">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label">imgSpan：</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" name="imgspan" placeholder="imgSpan">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"><span class="respan">*</span>排序:</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" name="orderno" placeholder="排序">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label">备注:</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" name="description" placeholder="备注">
                                </div>
                            </div>
                            <button type="reset" class="btn btn-default" style="display: none"
                                    id="editResetBtn"></button>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="savebtn btn btn-primary" id="editSaveBtn">保存</button>
                        <button type="button" class="cancelbtn btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
        <!--删除提示 modal -->
        <div class="modal fade" id="enshureModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
             data-backdrop=false>
            <div class="modal-dialog" role="document">
                <input type="hidden" id="deleteId" value=""/>
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">删除行</h4>
                    </div>
                    <div class="modal-body">
                        <p>确定删除吗？（该资源以及该资源下所属资源将全部被删除）</p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="csavebtn btn btn-primary">确定</button>
                        <button type="button" class="cancelbtn btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>
</div>
<script src="../../../assert/js/jquery.js" th:src="@{/assert/js/jquery.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/bootstrap.min.js" th:src="@{/assert/js/bootstrap.min.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<!--<script src="../../../assert/js/bootstrap-table.js" th:src="@{/assert/js/bootstrap-table.js}"></script>-->
<script src="../../../assert/js/plugin/bootstrap-table/bootstrap-table.min.js"
        th:src="@{/assert/js/plugin/bootstrap-table/bootstrap-table.min.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/bootstrap-select.js" th:src="@{/assert/js/bootstrap-select.js}"></script>
<script src="../../../assert/js/bootstrapValidator.js" th:src="@{/assert/js/bootstrapValidator.js}"></script>
<script src="../../../assert/js/toastr.min.js" th:src="@{/assert/js/toastr.min.js}"></script>
<script src="../../../assert/js/base.js" th:src="@{/assert/js/base.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/common.js" th:src="@{/assert/js/common.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script type="text/javascript">
    //项目名称
    var basePath = $("#basePath").attr("href");
    var TableInit = function () {
        var oTableInit = new Object();
        //初始化Table
        oTableInit.Init = function () {
            $('#resourceTable').bootstrapTable({
                url: basePath + "rest/resource/resourcesByPage", //请求后台的URL（*）
                method: "post", //请求方式（*）
                dataType: "json",
                contentType: "application/x-www-form-urlencoded;charset=UTF-8",
                dataField: "rows", //服务端返回数据键值 就是说记录放的键值是rows，分页时使用总记录数的键值为total
                totalField: "total",
                striped: true, //是否显示行间隔色
                cache: false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true, //是否显示分页（*）
                sortable: true, //是否启用排序
                sortName: "id", //排序方式
                sortOrder: "desc", //排序方式
                clickToSelect: true,
                queryParams: oTableInit.queryParams, //传递参数（*）
                queryParamsType: "", //  queryParamsType = 'limit' 参数: limit, offset, search, sort, order;
                sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1, //初始化加载第一页，默认第一页
                pageSize: 10, //每页的记录行数（*）
                pageList: [10, 15, 20, 25], //可供选择的每页的行数（*）
                idField: "id",
                uniqueId: "id", //每一行的唯一标识，一般为主键列
                columns: [{
                    field: 'id',
                    title: 'ID',
                    sortable: true,
                    visible: false
                },
                    {
                        field: 'checkStatus',
                        title: '全选',
                        checkbox: true
                    },
                    {
                        field: 'parentname',
                        title: '父级资源',
                        sortable: true
                    },
                    {
                        field: 'code',
                        title: '编码',
                        sortable: true
                    },
                    {
                        field: 'name',
                        title: '名称',
                        sortable: true
                    },
                    {
                        field: 'url',
                        title: '访问地址',
                        sortable: true
                    },
                    {
                        field: 'orderno',
                        title: '排序',
                        sortable: true
                    },
                    {
                        field: 'imgspan',
                        title: '图标',
                        sortable: true
                    },
                    {
                        field: 'type',
                        title: '类型',
                        sortable: true,
                        formatter: function (value, row, index) {
                            if (value == "0") {
                                return "菜单";
                            } else if (value == "1") {
                                return "功能";
                            } else {
                                return "页面";
                            }
                        }
                    },
                    {
                        field: 'status',
                        title: '状态',
                        sortable: true,
                        formatter: function (value, row, index) {
                            if (value == "0") return "停用";
                            else return "启用";
                        }
                    }
                ],
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () { //没有匹配的结果
                    return '无符合条件的记录';
                },
                onLoadSuccess: function (data) {  //加载成功时执行
                    resize.me();
                },
                onLoadError: function (data) {
                    $('#resourceTable').bootstrapTable('removeAll');
                },
                responseHandler: function (res) {
                    return {
                        total: res.totalCount,
                        rows: res.result
                    };
                }
            });
        };

        //得到查询的参数
        oTableInit.queryParams = function (params) {
            var temp = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                "pageSize": params.pageSize,
                "pageNum": params.pageNumber,
                "sortName": this.sortName,
                "sortOrder": this.sortOrder,
                "parentId": $("#parentIdSearch").val() != null ? $("#parentIdSearch").val().join(",") : null,
                "name": $.trim($("#nameSearch").val()),
                "code": $.trim($("#codeSearch").val())
            };
            return temp;
        };
        return oTableInit;
    };

    // 添加资源
    var resourceAddFun = {
        init: function () {
            resourceAddFun.formInit();
            resourceAddFun.save();
        },
        formInit: function () {
            // 在新增模态框显示出来前 初始化表单值
            $("#resourceModal").on("show.bs.modal", function () {
                $("#addSelect").html("<option value=\"\" selected>请选择</option>");
                $.get(basePath + "rest/resource/parentResourceAll", function (data) {
                    $.each(data, function (index, resource) {
                        $("#addSelect").append("<option value=\"" + resource.id + "\">" + resource.name + "</option>");
                    });
                    $("#addSelect").selectpicker('refresh');
                    $("#addSelect").selectpicker('render');
                });
                // 设置表单默认值
                $("#addResetBtn").click();
                // 设置类型默认选中菜单
                $("#addTypeSelect").val(0);
                $("#addTypeSelect").selectpicker('refresh');
            });
        },
        save: function () {
            // 新增资源保存按钮点击事件绑定
            $("#addSaveBtn").off("click").on("click", function () {
                var bv = $('#resouceForm').data('bootstrapValidator');
                bv.validate();
                if (bv.isValid()) {
                    //发送ajax请求
                    $.ajax({
                        type: "post",
                        url: basePath + "rest/resource/resourceAdd",
                        data: $("#resourceModal form").serialize(),
                        success: function (data) {
                            if (data.type == "success") {
                                $("#resourceModal").modal("hide");
                                // 提示新增成功
                                toastr.success("资源新增成功");
                                $("#resourceTable").bootstrapTable("refresh");
                            } else {
                                // 提示新增失败
                                toastr.error("资源新增失败");
                            }
                        }
                    });
                }
            });
        }
    };

    // 修改资源
    var resourceEditFun = {
        init: function () {
            resourceEditFun.openEditModal();
            resourceEditFun.formInit();
            resourceEditFun.save();
        },
        openEditModal: function () {
            $("#editBtn").off("click").on("click", function () {
                var rows = $("#resourceTable").bootstrapTable("getSelections");
                if (rows.length == 0) {
                    toastr.error('请选择行');
                } else if(rows.length > 1) {
                    toastr.error('单次只能选择一行进行修改');
                }else{
                    var id = rows[0].id;
                    $("#resourceId").val(id);
                    $("#editModal").modal("show");
                }
            });
        },
        formInit: function () {
            // 在修改模态框显示出来前 初始化表单值
            $("#editModal").on("show.bs.modal", function () {
                var id = $("#resourceId").val();
                $.ajax({
                    type: "post",
                    async: false,
                    url: basePath + "rest/resource/resourceGetByPK",
                    data: {id: id},
                    success: function (data) {
                        if (data != null) {
                            // 先初始化父级资源
                            var parentId = data.parentid;
                            var type = data.type;
                            $("#editSelect").html("<option value=\"\">请选择</option>");
                            // 若无父级资源且类型为菜单，则不允许修改父级资源，避免出现死循环
                            if (!parentId && type == 0){
                                $("#editSelect").selectpicker("refresh");
                                $("#editSelect").selectpicker("render");
                            } else {
                                $.get(basePath + "rest/resource/parentResourceAll", function (data) {
                                    $.each(data, function (index, resource) {
                                        if (resource.id == parentId) {
                                            $("#editSelect").append("<option value=\"" + resource.id + "\" selected>" + resource.name + "</option>");
                                        } else {
                                            $("#editSelect").append("<option value=\"" + resource.id + "\">" + resource.name + "</option>");
                                        }
                                    });
                                    $("#editSelect").selectpicker("refresh");
                                    $("#editSelect").selectpicker("render");
                                });
                            }
                            // 类型选择下拉框初始化
                            var type = data.type;
                            $("#editTypeSelect").val(type);
                            $("#editTypeSelect").selectpicker("refresh");
                            // 文本框值初始化
                            $("#editModal input[name='code']").val(data.code);
                            $("#editModal input[name='name']").val(data.name);
                            $("#editModal input[name='url']").val(data.url);
                            $("#editModal input[name='imgspan']").val(data.imgspan);
                            $("#editModal input[name='orderno']").val(data.orderno);
                            $("#editModal input[name='description']").val(data.description);
                        }
                    }
                });
            });
        },
        save: function () {
            // 修改资源保存按钮点击事件绑定
            $("#editSaveBtn").off("click").on("click", function () {
                var bv = $('#editResourceForm').data('bootstrapValidator');
                bv.validate();
                if (bv.isValid()) {
                    $.ajax({
                        type: "post",
                        url: basePath + "rest/resource/resourceUpdate",
                        data: $("#editModal form").serialize(),
                        success: function (data) {
                            if (data.type == "success") {
                                $("#editModal").modal("hide");
                                // 提示修改成功
                                toastr.success("资源修改成功");
                                $("#resourceTable").bootstrapTable("refresh");
                            } else {
                                // 提示修改失败
                                toastr.error("资源修改失败");
                            }
                        }
                    });
                }
            });
        }
    };

    // 状态修改
    var statusChangeFun = {
        init: function () {
            statusChangeFun.batchOn();
            statusChangeFun.batchOff();
        },
        batchOn: function () {
            // 批量启用按钮事件绑定
            $("#batchOnBtn").off("click").on("click", function () {
                statusChangeFun.batch(1);
            });
        },
        batchOff: function () {
            // 批量停用按钮事件绑定
            $("#batchOffBtn").off("click").on("click", function () {
                statusChangeFun.batch(0);
            });
        },
        batch: function (status) {
            // 先获取要启用或停用的资源id
            var rows = $("#resourceTable").bootstrapTable("getSelections");
            if (rows.length == 0) {
                toastr.error('请至少选择一条资源信息');
            } else {
                var idList = [];
                var statusStr = "";
                $.each(rows, function (index, row) {
                    idList.push(row.id);
                    statusStr += row.status;
                });
                if (statusStr.indexOf(status) > -1) {
                    var str = "";
                    if (status == 1) {
                        str = "启用"
                    } else {
                        str = "停用"
                    }
                    toastr.error('包含已' + str + "资源信息！");
                    return;
                }
                // 批量操作
                $.ajax({
                    type: "post",
                    url: basePath + "rest/resource/statusBatch",
                    data: {idList: idList, status: status},
                    traditional: true,
                    success: function (data) {
                        if (data.type == "success") {
                            toastr.success("资源状态批量修改成功");
                        } else {
                            toastr.error("资源状态批量修改失败");
                        }
                        $("#resourceTable").bootstrapTable("refresh");
                    }
                });
            }
        }
    };

    // 删除资源
    var resourceDeleteFun = {
        init: function () {
            resourceDeleteFun.batch();
            resourceDeleteFun.confimDelete();
        },
        batch: function () {
            // 批量删除按钮绑定事件
            $("#batchDeleteBtn").off("click").on("click", function () {
                $("#deleteId").val("");
                // 先获取选中的行
                var rows = $("#resourceTable").bootstrapTable("getSelections");
                if (rows.length == 0) {
                    toastr.error('请选择行');
                } else {
                    var ids = [];
                    var isCanDelete = true;
                    $.each(rows, function (index, row) {
                        if (row.status == 1) {
                            isCanDelete = false;
                        }
                        ids.push(row.id);
                    });
                    if (!isCanDelete) {
                        // 修改为模态框弹出
                        toastrCog.error("选中的资源为启用状态，不允许删除", 2000);
                        return false;
                    }
                    $("#deleteId").val(ids.join(","));
                    // 弹出删除确认模态框
                    $("#enshureModal").modal("show");
                }
            });
        },
        confimDelete: function () {
            // 在删除模态框中点击确定时触发的删除事件绑定
            $(".csavebtn").off("click").on("click", function () {
                var idList = $("#deleteId").val().split(",");
                $.ajax({
                    type: "post",
                    url: basePath + "rest/resource/resourceDeleteBatch",
                    data: {idList: idList},
                    traditional: true,
                    success: function (data) {
                        // 相应后关闭model框
                        $("#enshureModal").modal("hide");
                        if (data.type == "success") {
                            toastr.success('删除成功');
                        } else {
                            toastr.error('删除失败');
                        }
                        // 刷新表格
                        $("#resourceTable").bootstrapTable("refresh");
                    }
                });
            });
        }
    };
    //添加相关
    var validateFun = {
        init: function () {
            this.initKeyValidator();
            this.initOpen();
        },
        initKeyValidator: function () {
            var option = {
                live: "enabled",
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    code: {
                        validators: {
                            notEmpty: {
                                message: '编码不能为空'
                            }
                        }
                    },
                    name: {
                        validators: {
                            notEmpty: {
                                message: '名称不能为空'
                            }
                        }
                    },
                    /*url: {
                        validators: {
                            notEmpty: {
                                message: '访问地址/资源编码不能为空'
                            }
                        }
                    },
                    imgspan: {
                        validators: {
                            notEmpty: {
                                message: 'imgspan不能为空'
                            }
                        }
                    },*/
                    orderno: {
                        validators: {
                            notEmpty: {
                                message: '排序不能为空'
                            },
                            regexp: {
                                regexp : /^\d*$/,
                                message: '请输入整数数值'
                            }
                        }
                    }
                }
            };
            $("#resouceForm").bootstrapValidator(option);
            $("#editResourceForm").bootstrapValidator(option);
        },
        initOpen: function () {
            $("#resourceModal").on("hide.bs.modal", function () {
                $('#resouceForm').data('bootstrapValidator').resetForm(true);
            });

            $("#editModal").on("hide.bs.modal", function () {
                $('#editResourceForm').data('bootstrapValidator').resetForm(true);
            });
        }
    };

    // 基础功能
    var baseFun = {
        init: function () {
            baseFun.search();
            baseFun.parentResource();
            baseFun.reset();
        },
        // 点击搜索时表格重新加载
        search: function () {
            $("#searchBtn").off("click").on("click", function () {
                $("#resourceTable").bootstrapTable('refreshOptions', {pageNumber:1});
                 $("#resourceTable").bootstrapTable('refresh');
            });
            $("body").on("keyup", function (e) {
                var code = e.charCode || e.keyCode;
                if (code == 13) {
                    //此处编写用户敲回车后的代码
                    $("#resourceTable").bootstrapTable('refreshOptions', {pageNumber:1});
                    $("#resourceTable").bootstrapTable('refresh');
                }
            })
        },
        reset:function(){
            $("#reset").on("click", function () {
                bs.resetSearch($(".cquery"));
                $("#parentIdSearch").selectpicker("val","");
                $("#parentIdSearch").selectpicker("refresh");
                $("#resourceTable").bootstrapTable('refreshOptions', {pageNumber:1});
                $("#resourceTable").bootstrapTable('refresh');
            })
        },
        parentResource: function () {
            // 父级资源下拉框初始化
            $.get(basePath + "rest/resource/parentResourceAll", function (data) {
                $.each(data, function (index, resource) {
                    $("#parentIdSearch").append("<option value=\"" + resource.id + "\">" + resource.name + "</option>");
                });
                $('#parentIdSearch').selectpicker('refresh');
                $('#parentIdSearch').selectpicker('render');
            });
        }
    };

    var resize = {
        init: function () {
            resize.me();
            $(window).resize(function () {
                resize.me();
            })
        },
        me: function () {
            var winW = $(window).width();
            var winH = $(window).height();
            var winHh = document.documentElement.clientHeight
            $(".ibox").width(winW - 20);
            $(".ibox").height(winHh - 20);
            bs.autoTableHeight($('#resourceTable'),winH -$(".cquery").height()-22-$(".obtns").height())
        }
    };
    $(function () {
        // 表格初始化
        var oTable = new TableInit();
        oTable.Init();
        baseFun.init();
        // 新增
        resourceAddFun.init();
        // 修改
        resourceEditFun.init();
        // 启用、停用
        statusChangeFun.init();
        // 删除
        resourceDeleteFun.init();
        // 校验
        validateFun.init();
        resize.init();
    });
</script>
</body>

</html>